package com.qianfeng.dao;

import com.qianfeng.entity.Patient;
import com.qianfeng.entity.PatientSta;
import com.qianfeng.entity.ProSta;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PatientDao {

    /*<select id="queryProSta" resultType="com.qianfeng.entity.ProSta">*/
    /**
     * 查询所有省份，以及省份的相关患者统计数据。
     * @return
     */
    List<ProSta> queryProSta();

    List<ProSta> queryProStaByCity(String city);  //my

    List<ProSta> queryProStaByProvince(String province);  //my

    List<Patient> queryCityPatient(String city);

    List<Patient> queryProvincePatient(String province);  //my


    // CRUD
    Patient queryOneById(Integer id);

    int addPatient(Patient patient);

    int updatePatient(Patient patient);

    int deletePatient(Integer id);


    // -----------------------  市  ---------------------------------------------------------------
    /**
     * 获取累计数量
     * @param city
     * @return
     */
    @Select("select count(*) from patient where city = #{city}")  //累计确诊
    Integer getCityCount(@Param("city") String city);


    //昨日新增确诊
    @Select("select count(*) from patient where city=#{city} AND suretime BETWEEN STR_TO_DATE( DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s' ) and DATE_SUB(STR_TO_DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'),INTERVAL 1 SECOND)")
    Integer getCitySureYesterday(@Param("city") String city);

    //昨日新增死亡
    @Select("select count(*) from patient where city=#{city} AND dietime BETWEEN STR_TO_DATE( DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s' ) and DATE_SUB(STR_TO_DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'),INTERVAL 1 SECOND)")
    Integer getCityDieYesterday(@Param("city") String city);

    //昨日新增治愈
    @Select("select count(*) from patient where city=#{city} AND curetime BETWEEN STR_TO_DATE( DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s' ) and DATE_SUB(STR_TO_DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'),INTERVAL 1 SECOND)")
    Integer getCityCureYesterday(@Param("city") String city);

    /**
     * 根据状态查询
     * @param city
     * @param status
     * @return
     */
    @Select("select count(*) from patient where city=#{city} and patient_state= #{status}")  //现有确诊、死亡人数、治愈人数
    Integer getCityCountBysta(@Param("city") String city, @Param("status") String status);


    // -----------------------  省  ---------------------------------------------------------------
    /**
     * 获取累计数量
     * @param province
     * @return
     */
    @Select("select count(*) from patient where province = #{province}")  //累计确诊
    Integer getProvinceCount(@Param("province") String province);


    //昨日新增确诊
    @Select("select count(*) from patient where province=#{province} AND suretime BETWEEN STR_TO_DATE( DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s' ) and DATE_SUB(STR_TO_DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'),INTERVAL 1 SECOND)")
    Integer getProvinceSureYesterday(@Param("province") String province);

    //昨日新增死亡
    @Select("select count(*) from patient where province=#{province} AND dietime BETWEEN STR_TO_DATE( DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s' ) and DATE_SUB(STR_TO_DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'),INTERVAL 1 SECOND)")
    Integer getProvinceDieYesterday(@Param("province") String province);

    //昨日新增治愈
    @Select("select count(*) from patient where province=#{province} AND curetime BETWEEN STR_TO_DATE( DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s' ) and DATE_SUB(STR_TO_DATE(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'),INTERVAL 1 SECOND)")
    Integer getProvinceCureYesterday(@Param("province") String province);

    /**
     * 根据状态查询
     * @param
     * @param status
     * @return
     */
    @Select("select count(*) from patient where province=#{province} and patient_state= #{status}")  //现有确诊、死亡人数、治愈人数
    Integer getProvinceCountBysta(@Param("province") String province, @Param("status") String status);

}
